package gsw.demo.skin;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.io.File;

import gsw.tool.skin.SkinManager;
import gsw.tool.skin.utils.ToolFile;


/**
 * 一键换肤demo
 */
public class ActivitySkin extends Activity {
    private static final String TAG = "ActivitySkin";
    private String assetPath = "skin/demo.skin";
    private String newPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_skin);
        downloadSkin();
    }

    /**
     * 下载皮肤包
     */
    public void downloadSkin() {
        newPath = new File(getFilesDir(), assetPath).getAbsolutePath();
        if (ToolFile.isExist(newPath)) {
            return;
        }
        //下载皮肤包
        new Thread(new Runnable() {
            @Override
            public void run() {
                ToolFile.copyAssets(ActivitySkin.this, assetPath, newPath);
                Log.d(TAG, "onNext()");
            }
        }).start();
    }

    /**
     * 换皮肤
     *
     * @param view
     */
    public void change(View view) {
        SkinManager.getInstance().loadSkin(newPath);
    }

    /**
     * 还原皮肤
     *
     * @param view
     */
    public void restore(View view) {
        SkinManager.getInstance().loadSkin(null);
    }
}
